import Vue from 'vue'
import Router from 'vue-router'
import { routes } from '@/router/module/index'
import store from "@/store/index";
Vue.use(Router)

let router = new Router({
    routes: [...routes]
})

//轮询监听用户信息
const cycleGetUserInfo = res => {
    setInterval(res => {
        getUserInfo()
    }, 60000)
}
const getUserInfo = () => {
    if (window.localStorage.getItem("mobile")) {
        store.dispatch("addinfo");

    }
}

//用户信息
// cycleGetUserInfo()
// getUserInfo()

router.beforeEach((to, from, next) => {
    if (!localStorage.getItem('mobile')) {
        if (["/user/login", '/user/register', '/user/protocol', '/user/forget'].includes(to.path)) {
            next()
        } else {
            next('/user/login')
        }

    } else {
        next()
    }
})

export default router